﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>人员对应客户经理</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/setPeople.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/find.js"></script>   
<script type="text/javascript" src="../js/userSelecterNew.js"></script>   
<script type="text/javascript" src="../js/pagination.js"></script>   
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">

</style>
<script type="text/javascript" >
function bclicks(obj){
	var $first=obj.parent("td").parent("tr").children("td:first");
	var id=$first.html();
	var name=$first.next().html();
	//$("#shopName").children("option").blur();
	getParamToshopS(id,name)
}
var pagecount = 0;
var count = 0;
var shopId="shopId";
var shopPageCount=0;
var shopCount=0;
var mainShopId=0;
var pageIndex=1;

$(function(){
	refreshInput($(".serWrapper"));
	$("#shopIsChoosed").click(function(){
		if($("#shopIsChoosed").is(":checked")){
			$("#shopName").attr("disabled",false);
		}else{
			$("#shopName").attr("disabled",true);

		}
	})
	addMargin($("#window_change"));
	addMargin($("#Postset"));
	addMargin($("#personShop"));
	addMargin($("#personPost"));
	$("#shopName2").click(function(){
		$(this).blur();
		$("#personShop,#yinyingCenter").show();
	})
	
}); 


function shopExits(id){
	var bloo=false
	$("#shopName").find("option").each(function(){
		
		if($(this).attr("value")===id){
			bloo= true;
			return bloo;
		}
	})
	return bloo;
}
function getParamToshopS(id,name){
	var shopflag=$("#shopflag").val();
	if(shopflag==1){
	var htm="<option value='"+id+"'>"+name+"</option>"
	$("#shopName").html(htm);
	$("#shopName").val(id);
	}else if(shopflag==2){
		var flag=false;
		$("#ownShopList tbody tr").each(function(){
			var shopId=$(this).find("td:first").html();
			if(shopId==id){
				flag=true;
			}
		})
		if(flag){
			art.dialog({fixed:true, lock: true,content:"已选择该店铺",icon:'error',ok:true});	
			return false;
		}
		$("#ownShopList tbody").append("<tr></tr>");
		var htm;
		var doflag=$("#doflag").val()
			
		if(doflag==1){
		if(userType==0){
			var count=$("#ownShopList tbody tr").length;
			if(count==1){
			 htm="<td>"+id+"</td><td>"+name+"</td><td><input class='mainShop'  onclick='chooseMainShopId( $(this),"+id+")' class=\"del\" type=\"button\" value=\"所属\"><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
				mainShopId=id;
			}else{
				 htm="<td>"+id+"</td><td>"+name+"</td><td><input class='notMainShop'  onclick='chooseMainShopId( $(this),"+id+")' class=\"del\" type=\"button\" value=\"所属\"><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"	
			}
		}else{
		htm="<td>"+id+"</td><td>"+name+"</td><td><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
		}
		}else if(doflag==2){
		htm="<td>"+id+"</td><td>"+name+"</td><td><input onclick='deleteOwnShop($(this),"+id+")' class=\"del\" type=\"button\" value=\"删除\"></td>"
	
		}
		$("#ownShopList tbody tr:last").append(htm)
		addMargin($("#personShop"))

	}
	closeShopShow();
}

function chooseMainShopId(obj,id){
	$("#ownShopList tbody tr").each(function(){
		$(this).find("input:first").removeClass("mainShop").addClass("notMainShop");
	})
	obj.removeClass("notMainShop").addClass("mainShop");
	mainShopId=id;
}

function closeShopShow(){
	$("#shopShow,#yinying").hide();
	$("#searchName").val("")
}

function InitShopList(shopPageIndex){
	var shopName=$("#searchName").val();
	$.ajax({
		type : "post",
		async:false,
		data :'name='+shopName,
		datatype : "json",
		url : "../shop/find/shopList/" + shopPageIndex + "/5",
		success : function(data) {
			var rst = JSON.parse(data);
			if(IsEmpty(rst)){
				art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
				return false;
				}
				if(rst.state==0){
					$("#shopList tbody tr").remove();

					initShopTable(rst);
					$("table[id='shopList'] tbody tr").each(function(){
						$(this).children("td:last").css("text-align","center").append("<input type='button' class='common_btn' value='选择' onclick='bclicks($(this))'>");

					})	
					if(rst.result.len > 0){
						 var shu = rst.result.len;
						 shopCount = Math.ceil(shu/5);					
						 }else{
								shopCount==0;
						 }
					 $("#shopPager").pager({ pagenumber: ++shopPageIndex, pagecount: shopCount, buttonClickCallback: ShopPageClick });
					 addMargin($("#shopShow"));	
					 }else if(rst.state==1){
					art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
				}else{
					checkStateShowErrorMsgAndDealResult(data);
				}
		}	
	});
}
// ===========7897897===========
// 	"find/dutyList/{pageIndex}/{pageSize}"





function InitTable() {
	var phone=$("#phone").val().replace(/\s/gi,'');	
	var status=$("#status").val();
	var username=$("#username").val();
	var loginname=$("#loginname").val();
	var shopId="";
	var param='phone='+phone+"&status="+status+"&username="+username+"&loginname="+loginname;
	if($("#shopIsChoosed").is(":checked")){
		shopId=$("#shopName").val();		
		if(IsEmpty(shopId)){
			shopId = "";
			
		}
	}
//      if()
	$.ajax({
		type : "post",
		async:false,
		data :{'phone':phone,'status':status,'username':username,'loginname':loginname,'shopId':shopId},
		datatype : "json",
		url : "../user/find/userList/" + pageIndex + "/10",
		success : function(data) {
			var rst = JSON.parse(data);
						
					
					if(IsEmpty(rst)){
						art.dialog({fixed:true, lock: true,content:"查询出错",icon:'error',ok:true});	
						return false;
						}
						if(rst.state==0){
							$("#memberList tbody tr").remove();
							var obj = DealAndShowMsg(data,false,false);
							initTable(rst);	
							if(rst.result.len > 0){
								 var shu = rst.result.len;
							 	 pagecount = Math.ceil(shu/10);
							 	 $("#NoResult").hide();
							}else{
								$("#NoResult").show();
								pagecount=0;

							}
							 	$("#sup").html("共"+rst.result.len+"条");	
							 	$("#pager").pager({ pagenumber: pageIndex, pagecount: pagecount, buttonClickCallback: PageClick });
							
							 }else if(rst.state==1){
							art.dialog({fixed:true, lock: true,content:rst.msg,icon:'error',ok:true});	
						}else{
							checkStateShowErrorMsgAndDealResult(data);
						}				
		}	
	});
}

ShopPageClick = function(pageclickednumber) {
    $("#shopPager").pager({ pagenumber: --pageclickednumber, pagecount: pagecount, buttonClickCallback: PageClick });
    $("#result").html("Clicked Page " + pageclickednumber);
    InitShopList(pageclickednumber);
}

PageClick = function(pageclickednumber) {
   	pageIndex=pageclickednumber;
	InitTable();
}

function search(){
	InitTable();
}
function search2(){
	InitShopList(0);
}
function initTable(json){
	
	$("#memberList tbody").empty();
	for ( var i = 0; i < json.result.data.length; i++) {
		var htm="<tr>"
			htm+="<td><img src='"+ _getStringOfJson(i, json, "imageUrl")+"'/></td>"
			htm+="<td>"+_getStringOfJson(i, json, "Name")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "LoginName")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "Address")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "Mp")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "managerName")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "StatusName")+"</td>"
			htm+="<td>"+_getStringOfJson(i, json, "CreateFileTime")+"</td>"
			var id = _getIntOfJson(i, json, "ID")
			htm+="<td><input class=\"common_btn \" type=\"button\" value=\"设置经理\"  onclick=\"toUpdate("+id+")\"></td>"
			htm+="</tr>"
				$("#memberList tbody").append(htm)
	}

}

function toUpdate(id){
	$("#updateId").val(id)
	openUserListPanel(null);
}

function initShopTable(json){
	if(json!=null && json.state==0){
		var params = new Array("id", "name","mp","contact");
		Loadtable(json,params,"shopList");
	}
}
function initPostTable(json){
	if(json!=null && json.state==0){
// 		{"msg":"","state":0,"result":{"len":15,"head":["ShopName","id","Code","Name","ShopId"],"data":[["圣草实友会总部店",44,"E12","Ce",280000022],[null,43,"12","售后",null],[null,42,"11","销售员",null],[null,41,"11","董事长",null],[null,37,"7","系统管理员",null]]}}
		var params = new Array("ShopName", "Code","Name","contact");
		Loadtable(json,params,"PostList");
	}
}


function Loadtable(json, params, tableId,custmID){
	var phArray = new Array();
	var count = 0;
	var custmIDCount = 0;
	if (params != null) {
		$(params).each(function(pIndex, pData) {
			$.each(json.result.head, function(hIndex, hData) {
				if (pData == hData) {
					phArray[count++] = hIndex;
				}
			});
		});
	}
	 if(custmID==null){
		 custmID="";
	    }
	var custmIDArr = new Array(custmID.length);
	$(custmID).each(function(index, ffData) {
		$.each(json.result.head, function(ffIndex, fffData) {
			if (fffData == ffData) {
				custmIDArr[custmIDCount++] = ffIndex;
			}
		});
	});
	if (json.result.data != null) {
		$.each(json.result.data, function(index, dt) {
			$("table[id='" + tableId + "']").append("<tr></tr>");
			$(phArray).each(function(phIndex, data) {
				$.each($(dt), function(dtIndex, d) {
					if (dtIndex == data) {
						if (isHiddenFile(custmIDArr,data)){
// 							<input type="button" class="common_btn" value="修改">
// 				            <input type="button" class="del common_btn" value="删除"></td>
						    $("table[id='"+ tableId+ "'] tr:last").append("<td><input type='button' name='"+d+"' class='common_btn' onclick='showEditPersonnel(this.name)' value='修改'><input type='button' name='"+d+"' class='del common_btn' onclick='popPoint(this.name)' value='删除'></td>");
							}else{
							$("table[id='" + tableId + "'] tr:last").append("<td>" +  (d === null||d == "null" ? " " : d) + "</td>");
							}
					}
				});
			});
		});
	}
}




//===========编辑的部分===============

function showShopList(a){
	$("#shopflag").val(a);
	$("#shopName,#shopName2").blur();
	$("#shopShow,#yinying").show();
	InitShopList(0);
}

function  downRescouse(){
	var phone=$("#phone").val().replace(/\s/gi,'');	
	var status=$("#status").val();
	var shopId="";
	var param='phone='+phone+"&status="+status;
	if($("#shopIsChoosed").is(":checked")){

		
		shopId=$("#shopName").val();
		
		if(shopId!=""&&shopId!=null){
			param+="&shopId="+shopId;
		}
	}
	param+="&downType=7"
	window.location.href="../csvdown/down/csv/down?"+param
}

 function __userSelected(id,name){
	 var userId = $("#updateId").val();
	 var heads = new Array("managerId","id");
	 var datas = new Array(id,userId);
	 var jsong = _getJsonParseEditStr(heads, datas);
	 var dt = _editInfo("../user/edit/editManagerId", {'data':jsong});
	 if(IsNotEmpty(dt)&&dt.state==0){
		 closeUserListPanel()
		 InitTable()
	 }
 }
 
 function updateInfo (){
 }
 
 
 function resetForm(){
$("#close_this").attr("disabled",false);			
 $("#form input").val("");
 }
</script>
<style type="text/css">
table.member_list th, table.member_list td {
	padding: 4px 1px;
}
</style>
</head>

<body>
<input type="hidden" id="updateId" value="">
<div id="yinying"></div>
<div id="yinyingCenter"></div>
<div id="yinying1"></div>
<!-- InstanceBeginEditable name="EditRegion3" -->
<div id="personShop" class="hideDiv">
    <div class="closeTop"><span onclick="saveOwnShopIds()" class="closeThe"><img src="../images/close.png"></span></div>
      <table id="ownShopList" class="member_list" cellpadding="4" cellspacing="0" border="1" width="100%">
      <caption><strong>店铺列表</strong><input type="button" value="增加" class="common_btn" onclick="showShopList('2')"></caption>
        <thead>
          <tr>
            <th>店面序号</th>
            <th>店面名称</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
        	
        </tbody>
      </table>
      <div class="submit_btn">
	<input id="close_this" class="common_btn" type="button" value="保存信息" onclick="saveOwnShopIds();">
</div>
</div>

<div id="shopShow" class="hideDiv">
  <div style="float:right;margin-bottom:5px;width:20px;height:20px;line-height:20px;text-align:center;background-color:#eee;margin-bottom:5px;border:1px solid #ccc;" > <span style="cursor: pointer;font-size: 14px;" onclick="closeShopShow();" >X</span> </div>
  <div class="bottom_search">
    <div class="serWrapper"><input type="text" id="searchName" class="txt"><strong class="refresh" onclick="$('#searchName').val('')">清空</strong></div>
    <input type="button" style="width:auto;margin-left:5px;" value="查询" onclick="search2()" class="common_btn">
  </div>
  <table   id="shopList" cellpadding="4" cellspacing="0" border="1" width="100%">
    <thead>
      <tr>
        <th>店面ID</th>
        <th>店面名称</th>
        <th>电话</th>
        <th>操作</th>
      </tr>
    </thead>
  </table>
  <div id="shopPager"></div>
</div>
<div class="container" id="container">
  <div class="container_R fr">
    <div class="place">人员对应客户经理</div>
    <div class="member_search">
      <p><span>
        <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">
        店面：</span>
        <select id="shopName" disabled="disabled" onclick="showShopList(1)" style="height:20px;">
        </select>
        <span>姓名：</span>
        <input type="text" id="username" value="" class="absoluteTxt">
        <span>登录名：</span>
        <input type="text" id="loginname" value="" class="absoluteTxt">
        </p>
        <p>
        <span>手机号：</span>
        <input type="text" id="phone" class="absoluteTxt">  
      <span>状态：</span>
      <select id="status">
        <option value="">所有</option>
        <option value="0">正常</option>
        <option value="1">非正常</option>
      </select>
      <input type="button" value="查询" class="btn" onclick="search()">
      </p>
    </div>
    <table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
      <caption>
      <strong>人员列表 <span id="sup">共0条</span></strong>
      </caption>
      <thead>
        <tr>
        	<th >图片 </th>
          <th>姓名</th>
          <th >登录名</th>
          <th >地址</th>
          <th>手机</th>
			<th>对应客户经理</th>	
          <th >状态</th>
          <th >建档时间</th>
          <th >操作</th>
        </tr>
      </thead>
      <tbody>
       
      </tbody>
    </table>
     <div id="NoResult"  class="Nothing" style="text-align:center;display: none;">无符合条件的数据！</div>
    <div id="pager" style="float: right;"></div>
  </div>
  <div class="fc"></div>
</div>
<!-- InstanceEndEditable --> 
<script type="text/javascript" src="../js/header.js"></script> 
<script type="text/javascript" src="../js/left.js"></script> 
<script type="text/javascript" src="../js/footer.js"></script> 
<script type="text/javascript">
clearThis("absoluteTxt");
showTab(1,3);
</script>
</body>
<!-- InstanceEnd -->
</html>
